import io.grpc.stub.StreamObserver;
import com.example.rpc.LoginProto.*;

public class AuthServiceImpl extends AuthServiceGrpc.AuthServiceImplBase {
    
    @Override
    public void login(LoginRequest request, StreamObserver<LoginResponse> responseObserver) {
        String username = request.getUsername();
        String password = request.getPassword();
        
        // 这里进行你的验证逻辑，例如数据库查询
        boolean isValidUser = "user".equals(username) && "pass".equals(password);
        
        LoginResponse response;
        if (isValidUser) {
            response = LoginResponse.newBuilder()
                        .setMessage("Login successful")
                        .setSuccess(true)
                        .build();
        } else {
            response = LoginResponse.newBuilder()
                        .setMessage("Invalid username or password")
                        .setSuccess(false)
                        .build();
        }
        
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}